package com.dingtalk.dingbotmgr.model;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

@Entity
public class Task {

    private Integer id;

    private String name;

    private String description;

    private ChatBotMessage chatBotMessage;

    private Set<ChatBot> chatBotSet;

    private String cronExpression;

    private TaskStatus taskStatus;

    @Id
    @GeneratedValue
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "chatbotmessage_id")
    public ChatBotMessage getChatBotMessage() {
        return chatBotMessage;
    }

    public void setChatBotMessage(ChatBotMessage chatBotMessage) {
        this.chatBotMessage = chatBotMessage;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "task_chatbot", joinColumns = @JoinColumn(name = "task_id"),
        inverseJoinColumns = @JoinColumn(name = "chatbot_id"))
    public Set<ChatBot> getChatBotSet() {
        return chatBotSet;
    }

    public void setChatBotSet(Set<ChatBot> chatBotSet) {
        this.chatBotSet = chatBotSet;
    }

    public String getCronExpression() {
        return cronExpression;
    }

    public void setCronExpression(String cronExpression) {
        this.cronExpression = cronExpression;
    }

    @Enumerated(EnumType.ORDINAL)
    public TaskStatus getTaskStatus() {
        return taskStatus;
    }

    public void setTaskStatus(TaskStatus taskStatus) {
        this.taskStatus = taskStatus;
    }
}
